package com.pro.common.api.user.file.model.db;

import com.baomidou.mybatisplus.annotation.TableField;
import com.pro.common.api.CommonConst;
import com.pro.common.api.model.BaseUserIdModel;
import com.pro.common.api.model.auth.IUserDataClass;
import com.pro.common.api.model.auth.subaccount.IOpenSubChange;
import com.pro.common.api.user.file.enums.EnumFileNodeType;
import com.pro.common.api.user.file.enums.EnumFileStatus;
import com.pro.framework.javatodb.annotation.JTDField;
import com.pro.framework.javatodb.annotation.JTDTable;
import com.pro.framework.javatodb.constant.JTDConst;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "文件节点")
@JTDTable(sequences = {
        "KEY `idx_userId_deleted_createTime` (`user_id`,`deleted`,`create_time`)",
        "UNIQUE KEY `uk_userId_parentId_type_nodeName_deleted` (`user_id`, `parent_id`,`type`, `node_name`,(if((`deleted` = 0), 1, NULL)))",
        "UNIQUE KEY `uk_userId_logicalPath_deleted` (`user_id`, `logical_path`,(if((`deleted` = 0), 1, NULL)))",
        "KEY `idx_parentId` (`parent_id`)",
        "KEY `idx_ancestorPath` (`ancestor_path`)",
        "KEY `idx_logicalPath` (`logical_path`)",
}, module = CommonConst.Modules.userFile, entityId = 30002)
public class UserFileNode extends BaseUserIdModel implements IUserDataClass, IOpenSubChange {

    @Schema(description = "节点名称")
    private String nodeName;

    @Schema(description = "父级ID") // UserFileNodeId
    @JTDField(defaultValue = "0")
    private Long parentId;

    @Schema(description = "逻辑路径，例如 /documents/work/")
    private String logicalPath;

    @Schema(description = "祖先路径，用于快速统计，例如 /root/1/23/")
    private String ancestorPath;

    @Schema(description = "回收站批次ID")
    private Long recycleBatchId;

    @Schema(description = "创建人ID")
    private Long createdBy;

    @Schema(description = "功能标识")
    private String featureTag;

    @Schema(description = "节点类型：file / folder")
    @JTDField(type = JTDConst.EnumFieldType.int_, defaultValue = "0", entityClassKey = "value")
    private EnumFileNodeType type;

    @Schema(description = "文件大小（仅文件有效）")
    private Long sizeBytes;

    @Schema(description = "扩展名（仅文件有效）")
    private String extension;

    @Schema(description = "MIME类型（仅文件有效）")
    private String contentType;

    @Schema(description = "关联文件信息")
    @TableField(exist = false)
    private UserFile userFile;

    @Schema(description = "上级目录信息")
    @TableField(exist = false)
    private List<UserFileNode> parentList;
    @TableField(exist = false)
    @Schema(description = "上传后先生成一遍全路径反馈_方便业务操作")
    private String url;


    @Schema(description = "文件状态")
//    @JTDField(type = JTDConst.EnumFieldType.int_, defaultValue = "0", entityClassKey = "value")
    @TableField(exist = false)
    private EnumFileStatus status;
}
